home *** CD-ROM | disk | FTP | other *** search
- #include "AmiMirror.h"
-
- //--------------------------------------------------------------------
- // Make program's message with EasyRequest()
-
- LONG MakeRequest (ULONG title, ULONG text, ULONG buttons, APTR arg1, ...)
- {
- struct EasyStruct es = { sizeof(struct EasyStruct), 0L, NULL, NULL, NULL };
-
- es.es_Title = GETMES(title);
- es.es_TextFormat = GETMES(text);
- es.es_GadgetFormat = GETMES(buttons);
-
- DisplayBeep (NULL);
- return (EasyRequestArgs (NULL, &es, NULL, &arg1));
- }
- //--------------------------------------------------------------------
- // Translate DOS-error code into descriptor string
-
- STRPTR FaultStr (LONG error, STRPTR buffer)
- {
- Fault (error, GETMES(DOS_ERROR_STR), buffer, 2*FAULT_MAX);
- return (buffer);
- }
- //--------------------------------------------------------------------
- // Realise the memory allocated for the patterns' list
-
- void FreePatList (void)
- {
- struct Node *node;
-
- ObtainSemaphore (&Sema);
- while (node = RemTail (&PatList))
- FreeVec (node);
- ReleaseSemaphore (&Sema);
- }
- //--------------------------------------------------------------------
- // Realise work buffers of patched function
-
- void FreeWBuf (struct WorkBuf *wb, BOOL force)
- {
- if (wb->wb_inbuf)
- {
- FreeVec (wb->wb_inbuf);
- wb->wb_inbuf = NULL;
- }
- if (force)
- FreeVec (wb);
- }
- //--------------------------------------------------------------------
- // Allocate work buffers for patch function
- // !!! We must never rely upon that any task have enough stack space for all needed buffers!!!
-
- struct WorkBuf * AllocWBuf (void)
- {
- struct WorkBuf *wb;
-
- if (wb = AllocVec (sizeof(struct WorkBuf), MEMF_PUBLIC))
- {
- wb->wb_inbuf = NULL;
- wb->wb_inlen = 0L;
- }
- else
- MakeRequest (REQ_TITLE_ERROR, OUT_MEM, CANCEL_BUT, NULL);
- return (wb);
- }
- //--------------------------------------------------------------------
- // Trace patterns' list for suitable pattern
- struct PatternNode * TracePatList (ULONG function, struct WorkBuf *wb)
- {
- STRPTR str;
- struct Node *node;
-
- stcgfn (wb->wb_name, wb->wb_path);
- stcgfp (wb->wb_dir, wb->wb_path);
- ObtainSemaphore (&Sema);
- node = PatList.lh_Head;
- while (node->ln_Succ)
- {
- if (((struct PatternNode *)node)->pn_Function == function)
- {
- if (((struct PatternNode *)node)->pn_PatternMode == PAT_MODE_NAME)
- str = wb->wb_name;
- else if (((struct PatternNode *)node)->pn_PatternMode == PAT_MODE_DIR)
- str = wb->wb_dir;
- else if (((struct PatternNode *)node)->pn_PatternMode == PAT_MODE_PATH)
- str = wb->wb_path;
- else
- str = NULL;
- if (str && MatchPatternNoCase (((struct PatternNode *)node)->pn_Match, str))
- {
- ReleaseSemaphore (&Sema);
- return ((struct PatternNode *)node);
- }
- }
- node = node->ln_Succ;
- }
- ReleaseSemaphore (&Sema);
- return (NULL);
- }
-
- //--------------------------------------------------------------------
- // Load settings (patterns' list)
-
- BOOL LoadSets (void)
- {
- struct PatternNode *PN;
- struct SetsHeader SH;
- struct PatternHeader PH;
- BPTR SetsFH;
- BOOL patch_t, convert = FALSE, result = GAME_OVER;
- UBYTE dosfault[2*FAULT_MAX];
-
- patch_t = patch;
- patch = FALSE;
-
- FreePatList();
-
- if (SetsFH = Open (SETS_FILE, MODE_OLDFILE))
- {
- if (Read (SetsFH, &SH, sizeof(struct SetsHeader)) == sizeof(struct SetsHeader))
- {
- if (SH.sh_ID == SETS_ID)
- {
- if (SH.sh_version <= SETS_VERSION)
- {
- if (SH.sh_version < SETS_VERSION)
- convert = TRUE;
- if (SH.sh_amount > 0L)
- {
- result = ALL_RIGHT;
- while (SH.sh_amount--)
- {
- if (PN = AllocVec (sizeof(struct PatternNode), MEMF_PUBLIC | MEMF_CLEAR))
- {
- if ((Read (SetsFH, &PH, sizeof(struct PatternHeader)) != sizeof(struct PatternHeader)) ||
- (Read (SetsFH, PN->pn_Pattern, PH.ph_PatternSize) != PH.ph_PatternSize) ||
- (Read (SetsFH, PN->pn_Storage, PH.ph_StorageSize) != PH.ph_StorageSize) ||
- (Read (SetsFH, PN->pn_Password, PH.ph_PasswordSize) != PH.ph_PasswordSize))
- {
- MakeRequest (REQ_TITLE_ERROR, CANT_READ_SETS, CANCEL_BUT, SETS_FILE, FaultStr (IoErr(), dosfault));
- FreeVec (PN);
- result = GAME_OVER;
- break;
- }
- if (convert)
- PN->pn_Function = 0;
- else
- PN->pn_Function = PH.ph_Function;
- PN->pn_PatternMode = PH.ph_PatternMode;
- PN->pn_StorageMode = PH.ph_StorageMode;
- PN->pn_StorageMethod = PH.ph_StorageMethod;
- PN->pn_PerformCheck = PH.ph_PerformCheck;
- if (PN->pn_UseXPK = PH.ph_UseXPK)
- {
- strcpy (PN->pn_XPKName, PH.ph_XPKName);
- PN->pn_XPKMode = PH.ph_XPKMode;
- }
- if (ParsePatternNoCase (PN->pn_Pattern, PN->pn_Match, 2*FMSIZE+8) < 0L)
- {
- MakeRequest (REQ_TITLE_ERROR, CANT_PARSE, CANCEL_BUT, PN->pn_Pattern, FaultStr (IoErr(), dosfault));
- FreeVec (PN);
- result = GAME_OVER;
- break;
- }
- PN->pn_Node.ln_Name = PN->pn_Match;
- ObtainSemaphore (&Sema);
- AddTail (&PatList, (struct Node *)PN);
- ReleaseSemaphore (&Sema);
- }
- else
- {
- MakeRequest (REQ_TITLE_ERROR, OUT_MEM, CANCEL_BUT, NULL);
- result = GAME_OVER;
- break;
- }
- }
- }
- else
- MakeRequest (REQ_TITLE_ERROR, NOT_SETS_FILE, CANCEL_BUT, SETS_FILE);
- }
- else
- MakeRequest (REQ_TITLE_ERROR, NOT_SETS_FILE, CANCEL_BUT, SETS_FILE);
- }
- else
- MakeRequest (REQ_TITLE_ERROR, NOT_SETS_FILE, CANCEL_BUT, SETS_FILE);
- }
- else
- MakeRequest (REQ_TITLE_ERROR, CANT_READ_SETS, CANCEL_BUT, SETS_FILE, FaultStr (IoErr(), dosfault));
- Close (SetsFH);
- }
- else
- MakeRequest (REQ_TITLE_ERROR, CANT_OPEN_SETS, CANCEL_BUT, SETS_FILE, FaultStr (IoErr(), dosfault));
- if (result)
- patch = patch_t;
- return (result);
- }
- //--------------------------------------------------------------------
- // Check for directory and file in Storage place
-
- ULONG CheckStorage (struct WorkBuf *wb)
- {
- UBYTE temp[FMSIZE], ch;
- STRPTR t;
- BPTR lock;
- BOOL loop = TRUE;
-
- strcpy (temp, wb->wb_sdir);
- if (t = strchr (temp, ':'))
- {
- ch = t[1]; t[1] = '\0';
- if (lock = Lock (temp, ACCESS_READ))
- {
- t[1] = ch;
- UnLock (lock);
- }
- else
- {
- MakeRequest (REQ_TITLE_ERROR, CANT_LOCK, CANCEL_BUT, temp, FaultStr (IoErr(), wb->wb_fault));
- return (FUNK_CANCEL);
- }
- }
- else
- t = temp;
- while (loop)
- {
- if (t = strchr (t, '/'))
- *t = '\0';
- else
- loop = FALSE;
- switch (getfa (temp))
- {
- case 0 :
- if (_OSERR == ERROR_OBJECT_NOT_FOUND)
- {
- if (lock = CreateDir (temp))
- {
- UnLock (lock);
- break;
- }
- MakeRequest (REQ_TITLE_ERROR, CANT_CREATE, CANCEL_BUT, temp, FaultStr (IoErr(), wb->wb_fault));
- return (FUNK_CANCEL);
- }
- MakeRequest (REQ_TITLE_ERROR, CANT_LOCK, CANCEL_BUT, temp, FaultStr (_OSERR, wb->wb_fault));
- return (FUNK_CANCEL);
- case -1:
- MakeRequest (REQ_TITLE_ERROR, CANT_LOCK, CANCEL_BUT, temp, FaultStr (ERROR_OBJECT_WRONG_TYPE, wb->wb_fault));
- return (FUNK_CANCEL);
- }
- if (t)
- {
- *t = '/';
- t++;
- }
- }
- switch (getfa (wb->wb_spath))
- {
- case 0 :
- if (_OSERR == ERROR_OBJECT_NOT_FOUND)
- return (FUNK_NO);
- MakeRequest (REQ_TITLE_ERROR, CANT_LOCK, CANCEL_BUT, wb->wb_spath, FaultStr (_OSERR, wb->wb_fault));
- break;
- case 1 :
- MakeRequest (REQ_TITLE_ERROR, CANT_LOCK, CANCEL_BUT, temp, FaultStr (ERROR_OBJECT_WRONG_TYPE, wb->wb_fault));
- break;
- case -1:
- return (FUNK_YES);
- }
- return (FUNK_CANCEL);
- }
- //--------------------------------------------------------------------
- // Load of file needed for duplicate/backup
-
- BOOL PrepareFile (struct PatternNode *pnode, struct WorkBuf *wb)
- {
- BPTR fh;
- struct FileInfoBlock *fib;
- BOOL result = GAME_OVER;
-
- FreeWBuf (wb, FALSE);
- if (fib = AllocDosObject (DOS_FIB, NULL))
- {
- if (fh = OldOpen (wb->wb_path, MODE_OLDFILE))
- {
- if (ExamineFH (fh, fib))
- {
- if (fib->fib_DirEntryType < 0)
- {
- if (wb->wb_inbuf = AllocVec (wb->wb_inlen = fib->fib_Size, MEMF_PUBLIC))
- {
- if (Read (fh, wb->wb_inbuf, wb->wb_inlen) == wb->wb_inlen)
- result = ALL_RIGHT;
- else
- MakeRequest (REQ_TITLE_ERROR, CANT_READ, CANCEL_BUT, wb->wb_path, FaultStr (IoErr(), wb->wb_fault));
- }
- else
- MakeRequest (REQ_TITLE_ERROR, OUT_MEM, CANCEL_BUT, NULL);
- }
- }
- else
- MakeRequest (REQ_TITLE_ERROR, CANT_EXAM, CANCEL_BUT, wb->wb_path, FaultStr (IoErr(), wb->wb_fault));
- OldClose (fh);
- }
- else
- MakeRequest (REQ_TITLE_ERROR, CANT_OPEN, CANCEL_BUT, wb->wb_path, FaultStr (IoErr(), wb->wb_fault));
- FreeDosObject (DOS_FIB, fib);
- }
- else
- MakeRequest (REQ_TITLE_ERROR, OUT_MEM, CANCEL_BUT, NULL);
- return (result);
- }
- //--------------------------------------------------------------------
- // Compare duplicated/backuped file with already presented one
-
- BOOL PerformCheck (struct PatternNode *pnode, struct WorkBuf *wb)
- {
- BPTR fh;
- ULONG x;
- STRPTR sbuf = NULL;
- LONG sbuf_len, xerr;
- struct FileInfoBlock *fib;
- struct XpkFib *xfib;
- UBYTE xpkerr[XPKERRMSGSIZE];
- BOOL result = FALSE;
-
- if (pnode->pn_UseXPK)
- {
- if (xfib = XpkAllocObject (XPKOBJ_FIB, NULL))
- {
- if (XpkExamineTags (xfib, XPK_InName, wb->wb_spath, XPK_GetError, xpkerr, TAG_DONE))
- MakeRequest (REQ_TITLE_ERROR, CANT_EXAMXPK, CANCEL_BUT, wb->wb_spath, xpkerr);
- else
- {
- if ((xfib->xf_ULen != wb->wb_inlen) || (strcmp (xfib->xf_Packer, pnode->pn_XPKName)))
- result = TRUE;
- else
- {
- if (xerr = XpkUnpackTags (XPK_InName, wb->wb_spath,
- XPK_GetOutBuf, &sbuf,
- XPK_GetOutBufLen, &sbuf_len,
- XPK_OutMemType, MEMF_PUBLIC,
- XPK_Password, pnode->pn_Password,
- XPK_GetError, xpkerr,
- XPK_PassThru, TRUE,
- TAG_DONE))
- {
- if ((xerr == XPKERR_NEEDPASSWD) || (xerr == XPKERR_WRONGPW))
- result = TRUE;
- else
- MakeRequest (REQ_TITLE_ERROR, CANT_UNPACK, CANCEL_BUT, wb->wb_spath, xpkerr);
- }
- else
- {
- for (x = 0; x < wb->wb_inlen; x++)
- {
- if (wb->wb_inbuf[x] != sbuf[x])
- {
- result = TRUE;
- break;
- }
- }
- }
- if (sbuf)
- FreeMem (sbuf, sbuf_len);
- }
- }
- XpkFreeObject (XPKOBJ_FIB, xfib);
- }
- else
- MakeRequest (REQ_TITLE_ERROR, OUT_MEM, CANCEL_BUT, NULL);
- }
- else
- {
- if (fib = AllocDosObject (DOS_FIB, NULL))
- {
- if (fh = OldOpen (wb->wb_spath, MODE_OLDFILE))
- {
- if (ExamineFH (fh, fib))
- {
- if (fib->fib_Size == wb->wb_inlen)
- {
- if (sbuf = AllocVec (fib->fib_Size, MEMF_PUBLIC))
- {
- if (Read (fh, sbuf, fib->fib_Size) == fib->fib_Size)
- {
- for (x = 0; x < wb->wb_inlen; x++)
- {
- if (wb->wb_inbuf[x] != sbuf[x])
- {
- result = TRUE;
- break;
- }
- }
- }
- else
- MakeRequest (REQ_TITLE_ERROR, CANT_READ, CANCEL_BUT, wb->wb_spath, FaultStr (IoErr(), wb->wb_fault));
- FreeVec (sbuf);
- }
- else
- MakeRequest (REQ_TITLE_ERROR, OUT_MEM, CANCEL_BUT, NULL);
- }
- else
- result = TRUE;
- }
- else
- MakeRequest (REQ_TITLE_ERROR, CANT_EXAM, CANCEL_BUT, wb->wb_spath, FaultStr (IoErr(), wb->wb_fault));
- OldClose (fh);
- }
- else
- MakeRequest (REQ_TITLE_ERROR, CANT_OPEN, CANCEL_BUT, wb->wb_spath, FaultStr (IoErr(), wb->wb_fault));
- FreeDosObject (DOS_FIB, fib);
- }
- else
- MakeRequest (REQ_TITLE_ERROR, OUT_MEM, CANCEL_BUT, NULL);
- }
- return (result);
- }
- //--------------------------------------------------------------------
- // Rename file(s) in Storage place
-
- BOOL RenameSuffix (struct WorkBuf *wb)
- {
- UWORD x;
- STRPTR t_old, t_new;
- BPTR lock;
- UBYTE conv[8];
- UBYTE temp_old[FMSIZE];
- UBYTE temp_new[FMSIZE];
-
- t_old = stpcpy (temp_old, wb->wb_spath);
- t_new = stpcpy (temp_new, wb->wb_spath);
- *t_old = '.'; t_old++;
- *t_new = '.'; t_new++;
- // delete file with suffix '99'
- stci_d (conv, x = 99);
- strcpy (t_old, conv);
- if (lock = Lock (temp_old, ACCESS_READ))
- {
- UnLock (lock);
- if (! OldDeleteFile (temp_old))
- {
- MakeRequest (REQ_TITLE_ERROR, CANT_DELETE, CANCEL_BUT, temp_old, FaultStr (IoErr(), wb->wb_fault));
- return (FALSE);
- }
- }
- else if (IoErr() != ERROR_OBJECT_NOT_FOUND)
- {
- MakeRequest (REQ_TITLE_ERROR, CANT_LOCK, CANCEL_BUT, temp_old, FaultStr (IoErr(), wb->wb_fault));
- return (FALSE);
- }
- // rename file(s) with suffix (x-1) to file(s) with suffix x
- while (x)
- {
- x--;
- strcpy (temp_new, temp_old);
- stci_d (conv, x);
- strcpy (t_old, conv);
- if (Rename (temp_old, temp_new))
- continue;
- else if (IoErr() == ERROR_OBJECT_NOT_FOUND)
- continue;
- MakeRequest (REQ_TITLE_ERROR, CANT_RENAME, CANCEL_BUT, temp_old, FaultStr (IoErr(), wb->wb_fault));
- return (FALSE);
- }
- // rename file without suffix to file with suffix 0
- strcpy (temp_new, temp_old);
- t_old[-1] = '\0';
- if (Rename (temp_old, temp_new))
- return (TRUE);
- if (IoErr() == ERROR_OBJECT_NOT_FOUND)
- return (TRUE);
- MakeRequest (REQ_TITLE_ERROR, CANT_RENAME, CANCEL_BUT, temp_old, FaultStr (IoErr(), wb->wb_fault));
- return (FALSE);
- }
- //--------------------------------------------------------------------
- // Save duplicated/backuped file
-
- void SaveFile (struct PatternNode *pnode, struct WorkBuf *wb)
- {
- BPTR fh;
- STRPTR buf = NULL, sbuf = NULL;
- LONG len, s_len, sbuf_len;
- UBYTE xpkerr[XPKERRMSGSIZE];
-
- if (pnode->pn_UseXPK)
- {
- if (XpkPackTags (XPK_InBuf, wb->wb_inbuf,
- XPK_InLen, wb->wb_inlen,
- XPK_GetOutBuf, &sbuf,
- XPK_GetOutLen, &s_len,
- XPK_GetOutBufLen, &sbuf_len,
- XPK_OutMemType, MEMF_PUBLIC,
- XPK_PackMethod, pnode->pn_XPKName,
- XPK_PackMode, pnode->pn_XPKMode,
- XPK_Password, pnode->pn_Password,
- XPK_GetError, xpkerr,
- TAG_DONE))
- MakeRequest (REQ_TITLE_ERROR, CANT_PACK, CANCEL_BUT, xpkerr);
- else
- {
- buf = sbuf;
- len = s_len;
- }
- }
- else
- {
- buf = wb->wb_inbuf;
- len = wb->wb_inlen;
- }
- if (buf)
- {
- if (fh = OldOpen (wb->wb_spath, MODE_NEWFILE))
- {
- if (Write (fh, buf, len) != len)
- MakeRequest (REQ_TITLE_ERROR, CANT_WRITE, CANCEL_BUT, wb->wb_spath, FaultStr (IoErr(), wb->wb_fault));
- OldClose (fh);
- }
- else
- MakeRequest (REQ_TITLE_ERROR, CANT_OPEN, CANCEL_BUT, wb->wb_spath, FaultStr (IoErr(), wb->wb_fault));
- }
- if (sbuf)
- FreeMem (sbuf, sbuf_len);
- }
- //--------------------------------------------------------------------
- // Create duplicated copy of file
-
- LONG SpareIt (BPTR file, struct PatternNode *pnode, struct WorkBuf *wb)
- {
- STRPTR t;
- LONG result;
- ULONG f_pres;
- UBYTE temp[FMSIZE];
-
- if (! (result = OldClose (file)))
- return (result);
- if (! PrepareFile (pnode, wb))
- return (result);
-
- if (pnode->pn_StorageMode == STO_MODE_FILE)
- strcpy (wb->wb_sdir, pnode->pn_Storage);
- else if (pnode->pn_StorageMode == STO_MODE_DIR)
- {
- strcpy (temp, wb->wb_dir);
- if (t = strchr (temp, ':'))
- *t = '/';
- strmfp (wb->wb_sdir, pnode->pn_Storage, temp);
- }
- else
- return (result);
- strmfp (wb->wb_spath, wb->wb_sdir, wb->wb_name);
- if (! (f_pres = CheckStorage (wb)))
- return (result);
- if ((f_pres == FUNK_YES) && (pnode->pn_PerformCheck))
- {
- if (! PerformCheck (pnode, wb))
- return (result);
- }
- if (pnode->pn_StorageMethod == STO_METHOD_REPLACE)
- {
- if (! OldDeleteFile (wb->wb_spath))
- {
- if (IoErr() != ERROR_OBJECT_NOT_FOUND)
- {
- MakeRequest (REQ_TITLE_ERROR, CANT_DELETE, CANCEL_BUT, wb->wb_spath, FaultStr (IoErr(), wb->wb_fault));
- return (result);
- }
- }
- }
- else if (pnode->pn_StorageMethod == STO_METHOD_SUFFIX)
- {
- if (! RenameSuffix (wb))
- return (result);
- }
- else
- return (result);
- SaveFile (pnode, wb);
- return (result);
- }
- //--------------------------------------------------------------------
- // Create backuped copy of wrote file
-
- BPTR BackupIt (STRPTR Name, LONG AccessMode, struct PatternNode *pnode, struct WorkBuf *wb)
- {
- STRPTR t;
- ULONG f_pres;
- UBYTE temp[FMSIZE];
-
- if (! PrepareFile (pnode, wb))
- return (OldOpen (Name, AccessMode));
-
- if (pnode->pn_StorageMode == STO_MODE_FILE)
- strcpy (wb->wb_sdir, pnode->pn_Storage);
- else if (pnode->pn_StorageMode == STO_MODE_DIR)
- {
- strcpy (temp, wb->wb_dir);
- if (t = strchr (temp, ':'))
- *t = '/';
- strmfp (wb->wb_sdir, pnode->pn_Storage, temp);
- }
- else
- return (OldOpen (Name, AccessMode));
- strmfp (wb->wb_spath, wb->wb_sdir, wb->wb_name);
- if (! (f_pres = CheckStorage (wb)))
- return (OldOpen (Name, AccessMode));
-
- if ((f_pres == FUNK_YES) && (pnode->pn_PerformCheck))
- {
- if (! PerformCheck (pnode, wb))
- return (OldOpen (Name, AccessMode));
- }
-
- if (pnode->pn_StorageMethod == STO_METHOD_REPLACE)
- {
- if (! OldDeleteFile (wb->wb_spath))
- {
- if (IoErr() != ERROR_OBJECT_NOT_FOUND)
- {
- MakeRequest (REQ_TITLE_ERROR, CANT_DELETE, CANCEL_BUT, wb->wb_spath, FaultStr (IoErr(), wb->wb_fault));
- return (OldOpen (Name, AccessMode));
- }
- }
- }
- else if (pnode->pn_StorageMethod == STO_METHOD_SUFFIX)
- {
- if (! RenameSuffix (wb))
- return (OldOpen (Name, AccessMode));
- }
- else
- return (OldOpen (Name, AccessMode));
- SaveFile (pnode, wb);
- return (OldOpen (Name, AccessMode));
- }
- //--------------------------------------------------------------------
- // Create backuped copy of deleted file
-
- BOOL AntiDelIt (STRPTR Name, struct PatternNode *pnode, struct WorkBuf *wb)
- {
- STRPTR t;
- ULONG f_pres;
- UBYTE temp[FMSIZE];
-
- if (! PrepareFile (pnode, wb))
- return (OldDeleteFile (Name));
-
- if (pnode->pn_StorageMode == STO_MODE_FILE)
- strcpy (wb->wb_sdir, pnode->pn_Storage);
- else if (pnode->pn_StorageMode == STO_MODE_DIR)
- {
- strcpy (temp, wb->wb_dir);
- if (t = strchr (temp, ':'))
- *t = '/';
- strmfp (wb->wb_sdir, pnode->pn_Storage, temp);
- }
- else
- return (OldDeleteFile (Name));
- strmfp (wb->wb_spath, wb->wb_sdir, wb->wb_name);
- if (! (f_pres = CheckStorage (wb)))
- return (OldDeleteFile (Name));
-
- if ((f_pres == FUNK_YES) && (pnode->pn_PerformCheck))
- {
- if (! PerformCheck (pnode, wb))
- return (OldDeleteFile (Name));
- }
-
- if (pnode->pn_StorageMethod == STO_METHOD_REPLACE)
- {
- if (! OldDeleteFile (wb->wb_spath))
- {
- if (IoErr() != ERROR_OBJECT_NOT_FOUND)
- {
- MakeRequest (REQ_TITLE_ERROR, CANT_DELETE, CANCEL_BUT, wb->wb_spath, FaultStr (IoErr(), wb->wb_fault));
- return (OldDeleteFile (Name));
- }
- }
- }
- else if (pnode->pn_StorageMethod == STO_METHOD_SUFFIX)
- {
- if (! RenameSuffix (wb))
- return (OldDeleteFile (Name));
- }
- else
- return (OldDeleteFile (Name));
- SaveFile (pnode, wb);
- return (OldDeleteFile (Name));
- }
- //--------------------------------------------------------------------
- // Replace function for dos Close()
-
- LONG __saveds __asm NewClose (register __d1 BPTR File)
- {
- BPTR lock;
- LONG result;
- struct PatternNode *node;
- struct WorkBuf *wb;
-
- if (patch)
- {
- if (wb = AllocWBuf())
- {
- if (NameFromFH (File, wb->wb_path, FMSIZE))
- {
- if (lock = DupLockFromFH (File))
- UnLock (lock);
- else if (node = TracePatList (FUNCTION_SPARE, wb))
- {
- result = SpareIt (File, node, wb);
- FreeWBuf (wb, TRUE);
- return (result);
- }
- }
- FreeWBuf (wb, TRUE);
- }
- }
- return (OldClose (File));
- }
- //--------------------------------------------------------------------
- // Replace function for dos Open()
-
- BPTR __saveds __asm NewOpen (register __d1 STRPTR Name, register __d2 LONG AccessMode)
- {
- BPTR lock, result;
- struct PatternNode *node;
- struct WorkBuf *wb;
-
- if (patch && (AccessMode != MODE_OLDFILE))
- {
- if (lock = Lock (Name, ACCESS_READ))
- {
- if (wb = AllocWBuf())
- {
- if (NameFromLock (lock, wb->wb_path, FMSIZE))
- {
- UnLock (lock);
- if (node = TracePatList (FUNCTION_BACKUP, wb))
- {
- result = BackupIt (Name, AccessMode, node, wb);
- FreeWBuf (wb, TRUE);
- return (result);
- }
- }
- else
- UnLock (lock);
- FreeWBuf (wb, TRUE);
- }
- else
- UnLock (lock);
- }
- }
- return (OldOpen (Name, AccessMode));
- }
- //--------------------------------------------------------------------
- // Replace function for dos DeleteFile()
-
- BOOL __saveds __asm NewDeleteFile (register __d1 STRPTR Name)
- {
- BPTR lock;
- BOOL result;
- struct PatternNode *node;
- struct WorkBuf *wb;
-
- if (patch)
- {
- if (lock = Lock (Name, ACCESS_READ))
- {
- if (wb = AllocWBuf())
- {
- if (NameFromLock (lock, wb->wb_path, FMSIZE))
- {
- UnLock (lock);
- if (node = TracePatList (FUNCTION_ANTIDEL, wb))
- {
- result = AntiDelIt (Name, node, wb);
- FreeWBuf (wb, TRUE);
- return (result);
- }
- }
- else
- UnLock (lock);
- FreeWBuf (wb, TRUE);
- }
- else
- UnLock (lock);
- }
- }
- return (OldDeleteFile (Name));
- }
- //--------------------------------------------------------------------
- // Main work cycle of program
-
- void MainLoop (void)
- {
- struct Message *msg;
- struct Task *PrefsTask;
- ULONG Sig, MsgID, MsgType;
- LONG retcode = 1L;
-
- patch = TRUE;
- while (retcode)
- {
- Sig = Wait (SIGBREAKF_CTRL_C | cxsigflag);
- while (msg = GetMsg (broker_mp))
- {
- MsgID = CxMsgID ((CxMsg *)msg);
- MsgType = CxMsgType ((CxMsg *)msg);
- if (MsgType == CXM_COMMAND)
- { // commodity messages
- ReplyMsg (msg);
- switch (MsgID)
- {
- case CXCMD_DISABLE : // temporaly disabling of commodity
- ActivateCxObj (broker, patch = FALSE);
- break;
- case CXCMD_ENABLE : // work again
- ActivateCxObj (broker, patch = TRUE);
- break;
- case CXCMD_KILL : // stop commodity and quit
- retcode = 0L;
- break;
- case CXCMD_UNIQUE : // run preferences editor
- case CXCMD_APPEAR :
- SystemTags (ArgString (ttypes, PREFS_TOOLTYPES, PREFS_DEFAULT_PATH), SYS_Asynch, TRUE, TAG_DONE);
- break;
- case CXCMD_DISAPPEAR : // close preferences editor
- if (PrefsTask = FindTask (TASK_PREFS_NAME))
- Signal (PrefsTask, SIGBREAKF_CTRL_C);
- break;
- }
- }
- else
- { // other messages
- if (! strcmp (msg->mn_Node.ln_Name, PREFS_PORT_NAME))
- retcode = LoadSets(); // message from preferences editor - reload settings
- ReplyMsg (msg);
- }
- }
- if (Sig & SIGBREAKF_CTRL_C)
- retcode = 0L; // break signal - quit
- }
- patch = FALSE;
- }
- /* ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¯
- ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¥ main() ª¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¯
- ¢ ¿¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡´ ¢
- ¿¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡´
- */
- void main (ULONG argc, STRPTR *argv)
- {
- LONG x;
- struct Message *msg;
-
- if (IntuitionBase = OpenLibrary (INTUITION_LIBRARY_NAME, INTUITION_LIBRARY_VERSION))
- {
- if (LocaleBase = OpenLibrary (LOCALE_LIBRARY_NAME, LOCALE_LIBRARY_VERSION))
- {
- if (catalog = OpenCatalog (NULL, GETMES(CATALOG_NAME), OC_Version, CATALOG_LAST_VERSION, OC_BuiltInLanguage, GETMES(BUILTIN_LANGUAGE), TAG_DONE))
- {
- for (x = PROG_DESC; x < FINISH; x++)
- messages[x] = GetCatalogStr (catalog, x, GETMES(x));
- }
- }
- if (XpkBase = OpenLibrary (XPK_LIBRARY_NAME, XPK_LIBRARY_VERSION))
- {
- ttypes = ArgArrayInit (argc, argv);
- newbroker.nb_Descr = GETMES(PROG_DESC);
- if (broker_mp = CreatePort (COM_PORT_NAME, 0))
- {
- newbroker.nb_Port = broker_mp;
- if (broker = CxBroker (&newbroker, &x))
- {
- cxsigflag = 1L << broker_mp->mp_SigBit;
- ActivateCxObj (broker, 1L);
- NewList (&PatList);
- InitSemaphore (&Sema);
- if (LoadSets())
- {
- OldOpen = (BPTR __asm (*)())SetFunction (DOSBase, (LONG)&LVOOpen, (APTR)NewOpen);
- OldClose = (LONG __asm (*)())SetFunction (DOSBase, (LONG)&LVOClose, (APTR)NewClose);
- OldDeleteFile = (BOOL __asm (*)())SetFunction (DOSBase, (LONG)&LVODeleteFile, (APTR)NewDeleteFile);
- MainLoop();
- SetFunction (DOSBase, (LONG)&LVODeleteFile, (APTR)OldDeleteFile);
- SetFunction (DOSBase, (LONG)&LVOClose, (APTR)OldClose);
- SetFunction (DOSBase, (LONG)&LVOOpen, (APTR)OldOpen);
- }
- FreePatList();
- DeleteCxObj (broker);
- }
- while (msg = GetMsg (broker_mp))
- ReplyMsg (msg);
- DeletePort (broker_mp);
- }
- else
- MakeRequest (REQ_TITLE_ERROR, CANT_MSGPORT, QUIT_BUT, NULL);
- ArgArrayDone();
- CloseLibrary (XpkBase);
- }
- else
- MakeRequest (REQ_TITLE_ERROR, LIBRARY_PROBLEM, QUIT_BUT, XPK_LIBRARY_NAME, XPK_LIBRARY_VERSION);
- if (LocaleBase)
- {
- CloseCatalog (catalog);
- CloseLibrary (LocaleBase);
- }
- CloseLibrary (IntuitionBase);
- }
- }
-